package com.kuanter.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.entity.Consumption;

/**
 * 消费记录适配器
 * 
 * @author soup
 * 
 */
public class Lv_xfjlAdapter extends BaseAdapter {

	private List<Consumption> consumptions = null;
	private Context context = null;

	public Lv_xfjlAdapter(List<Consumption> consumptions, Context context) {
		this.consumptions = consumptions;
		this.context = context;
	}

	@Override
	public int getCount() {
		return consumptions.size();
	}

	@Override
	public Object getItem(int position) {
		return consumptions.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	// private void setTime(TextView tv_date_xfjl,String time){
	// // 2012-10-31 07:53:58
	// String[] strAll=time.split(" ");
	// String date=strAll[0];
	// String t=strAll[1];
	// String yr[]=date.split("-");
	// String sf[]=t.split(":");
	//
	// tv_date_xfjl.setText(yr[1]+"月"+yr[2]+"日"+sf[0]+"时"+sf[1]+"分");
	// }

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if (convertView == null) {
			holder = new Holder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.lv_xfjl_item, null);
			holder.tv_date_xfjl = (TextView) convertView
					.findViewById(R.id.tv_date_xfjl);
			holder.tv_cardnum_xfjl = (TextView) convertView
					.findViewById(R.id.tv_cardnum_xfjl);
			holder.tv_jifen_xfjl = (TextView) convertView
					.findViewById(R.id.tv_jifen_xfjl);
			holder.tv_md_xfjl = (TextView) convertView
					.findViewById(R.id.tv_md_xfjl);

			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}

		Consumption c = consumptions.get(position);
		String time = c.getConsumptionTime();
		String card = c.getConsumptionCard();
		String amount = c.getConsumptionAmount();
		String shop = c.getConsumptionShop();

		if (time != null && !time.equals("")) {
			holder.tv_date_xfjl.setText(c.getConsumptionTime());
		} else {
			holder.tv_date_xfjl.setText("");
		}

		if (card != null && !card.equals("")) {
			holder.tv_cardnum_xfjl.setText(c.getConsumptionCard());
		} else {
			holder.tv_cardnum_xfjl.setText("");
		}

		if (amount != null && !amount.equals("")) {
			holder.tv_jifen_xfjl.setText("积分消费" + c.getConsumptionAmount()
					+ "分");
		} else {
			holder.tv_jifen_xfjl.setText("");
		}

		if (shop != null && !shop.equals("")) {
			holder.tv_md_xfjl.setText(c.getConsumptionShop());
		} else {
			holder.tv_md_xfjl.setText("");
		}

		return convertView;
	}

	class Holder {
		TextView tv_date_xfjl;
		TextView tv_cardnum_xfjl;
		TextView tv_jifen_xfjl;
		TextView tv_md_xfjl;
	}

}
